package it.antonio.ilpizze.aop;


import java.util.Arrays;
import java.util.List;

public class Proxifier {
        
        private List<Aspect> aspects;
        private ProxyFactory factory;
       
        
        public Proxifier(Driver driver, List<Aspect> aspects) {
			this.aspects = aspects;
			switch (driver) {
				case CGLIB: factory = new CGLibProxyFactory();break;
				default: throw new AopException("Driver not supported");
			}
		}

		public <T> T createInstance(Class<T> clazz, Object... params) {
                return factory.proxifyInstance(clazz, params, aspects);
        }
		
		public <T> Class<T> createClass(Class<T> clazz) {
            return factory.proxifyClass(clazz, aspects);
		}
        
		public static Proxifier withAspects(List<Aspect>  aspects){
                return new Proxifier(Driver.CGLIB, aspects);
        }
        public static Proxifier withAspects(Aspect...  aspects){
            return new Proxifier(Driver.CGLIB, Arrays.asList(aspects));
        }       
        
        public static Proxifier withAspects(Driver driver, List<Aspect>  aspects){
            return new Proxifier(driver, aspects);
        }
        public static Proxifier withAspects(Driver driver, Aspect...  aspects){
        	return new Proxifier(driver, Arrays.asList(aspects));
        }       
    
}
